"""
retrieve.py 包含recall的父类,其中包含
1.获取query模板
2.拼接query需求
3.处理query结果
4.判断query是否正常执行
5.
"""
import threading


class BaseRetrieve(threading.Thread):
    def __init__(self, config):
        super().__init__()
        self.config = config
        self.args = None

    def init(self, *args):
        self.args = args

    def get_query_template(self):
        """
        获取当前retrieve的基础模板
        :return:
        """

    def complete_query(self, global_resource, request_content, response_content):
        """
        填充模板,得到完整的query
        :return:
        """
        pass

    def process_result(self, global_resource, request_content, response_content):
        """
        处理retrieve result ,将其放入合适位置,base类不实现
        :return:
        """
        pass

    def do_retrieve(self, global_resource, request_content, response_content):
        # 将query_template 存入资源中
        #####
        body = self.complete_query(global_resource, request_content, response_content)
        es_service = global_resource.resource_manager.get_service("es_client")
        data_list = es_service.post_query("apis", "apis", body)
        # 处理result ,存入response_content
        response_content.retrieve_result[self.__class__.__name__+"_result"] = data_list

    def run(self) -> None:
        if not self.args:
            print("retrieve service start without init")
            return
        self.do_retrieve(*self.args)


